﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Threading;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
using System.Diagnostics;

namespace 第五次作业
{
    internal class crawpage
    {
        public List<string> crawUrl(string url)
        {
            List<string> urllist = new List<string>();

            WebClient client = new WebClient();
            client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
            Stream data = client.OpenRead(url);
            StreamReader reader = new StreamReader(data);
            string s = reader.ReadToEnd();
            data.Close();
            reader.Close();

            MatchCollection matches = Regex.Matches(s, @"http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?", RegexOptions.IgnoreCase);
            foreach (Match match in matches)
            {
                urllist.Add(match.Value.ToString());
            }

            return urllist;
        }
        
        public void crawEmail(string url, List<string> emaillist)
        {
            try
            {
                WebClient client = new WebClient();
                client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
                Stream data = client.OpenRead(url);
                StreamReader reader = new StreamReader(data);
                string s = reader.ReadToEnd();
                data.Close();
                reader.Close();

                MatchCollection matches = Regex.Matches(s, @"1[0-9]{10}");

                foreach (Match match in matches)
                {
                    emaillist.Add(match.ToString());
                }
            }
            catch (Exception ex)
            {
          
            }
        }
    }
}
